package com.lanou.wuyou.gift.list;

import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import com.lanou.wuyou.gift.R;
import com.lanou.wuyou.gift.base.BaseFragment;
import com.lanou.wuyou.gift.bean.ListBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 17/3/16.
 */

public class ListFragment extends BaseFragment{
    private String[] titles = {"每日推荐","TOP100","独立原创"};
    private ViewPager viewPager;
    private TabLayout tabLayout;
    private ListVPAdapter adapter;
    private List<ListBean> data;

    public static ListFragment newInstance(){
        Bundle args = new Bundle();
        ListFragment fragment = new ListFragment();
        fragment.setArguments(args);
        return fragment;
    }
    private String[] urls = {
            "http://api.liwushuo.com/v2/ranks_v3/ranks/1?limit=20&offset=",
            "http://api.liwushuo.com/v2/ranks_v3/ranks/2?limit=20&offset=",
            "http://api.liwushuo.com/v2/ranks_v2/ranks/3?limit=20&offset=0",
//            "http://api.liwushuo.com/v2/ranks_v2/ranks/4?limit=20&offset=0",
    };
    @Override
    public int setLayout() {
        return R.layout.fragment_list;
    }

    @Override
    public void initView(View view) {
        adapter = new ListVPAdapter(getChildFragmentManager());
        viewPager = (ViewPager)view.findViewById(R.id.view_pager_list);
        tabLayout = (TabLayout) view.findViewById(R.id.tab_layout_list);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);

        tabLayout.setTabTextColors(Color.parseColor("#949494"),Color.parseColor("#e63b4b"));
        tabLayout.setBackgroundColor(Color.WHITE);

        List<Fragment> fragments = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            fragments.add(ListListFragment.newInstance(urls[i]));
        }
        adapter.setFragments(fragments);
        for (int i = 0; i < titles.length; i++) {
            tabLayout.getTabAt(i).setText(titles[i]);
        }
    }

    @Override
    public void initData() {

    }
}
